package org.Vancl.Dao.ImpI;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.Vancl.Dao.lptDao;
import org.Vancl.entity.lpt;
import org.Vancl.utils.BaseDao;import org.eclipse.jdt.internal.compiler.flow.LoopingFlowContext;

public class lptDaoImpI extends BaseDao implements lptDao {

	
	public List<lpt> getAll() {
		String sql="SELECT * FROM lpt WHERE lpttype=1 ORDER BY lptid DESC";
		ResultSet rs=super.executeQuery(sql);
		List<lpt> lptlist=new ArrayList();
		try {
			while(rs.next()) {
				lpt lpt=new lpt();
				lpt.setLptid(rs.getInt("lptid"));
				lpt.setLptimage(rs.getString("lptimage"));
				lpt.setLptmiaoshu(rs.getString("lptmiaoshu"));
				lpt.setLpttype(rs.getInt("lpttype"));
				lptlist.add(lpt);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return lptlist;
	}

	@Override
	public int delete(int id) {
		String sql="delete from lpt where lptid=?";
		return super.executeUpdate(sql, id);
	}

	@Override
	public List<lpt> getzheng() {
		String sql="SELECT * FROM lpt";
		ResultSet rs=super.executeQuery(sql);
		List<lpt> lptlist=new ArrayList();
		try {
			while(rs.next()) {
				lpt lpt=new lpt();
				lpt.setLptid(rs.getInt("lptid"));
				lpt.setLptimage(rs.getString("lptimage"));
				lpt.setLptmiaoshu(rs.getString("lptmiaoshu"));
				lpt.setLpttype(rs.getInt("lpttype"));
				lptlist.add(lpt);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return lptlist;
	}

	@Override
	public int update(lpt lpt) {
		String sql="UPDATE lpt SET lptimage=?,lptmiaoshu=?,lpttype=? WHERE lptid=?";
		return super.executeUpdate(sql, lpt.getLptimage(),lpt.getLptmiaoshu(),lpt.getLpttype(),lpt.getLptid());
	}

	@Override
	public lpt getid(int id) {
		String sql="SELECT * FROM lpt where lptid=?";
		ResultSet rs=super.executeQuery(sql,id);
		lpt lpt=null;
		try {
			while(rs.next()) {
				lpt=new lpt();
				lpt.setLptid(rs.getInt("lptid"));
				lpt.setLptimage(rs.getString("lptimage"));
				lpt.setLptmiaoshu(rs.getString("lptmiaoshu"));
				lpt.setLpttype(rs.getInt("lpttype"));
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return lpt;
	}

	@Override
	public int add(lpt lpt) {
		String sql="INSERT INTO lpt(lptimage,lptmiaoshu,lpttype) values(?,?,?)";
		return super.executeUpdate(sql, lpt.getLptimage(),lpt.getLptmiaoshu(),lpt.getLpttype());
	}

}
